home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / commio0b.zip / DFUNIT.PAS < prev    next >
Pascal/Delphi Source File  |  1996-05-13  |  14KB  |  422 lines

  1. {$V-,O+,F+}
  2.     {^..^ overlay it; since the routines here are only used once, theres no
  3.           need for the code to sit in memory, if not being used. }
  4. unit DFunit; {Drop file unit}
  5. {
  6.          This unit is a companion to the COMMIO communications kit.
  7.                 Written by Jason Morriss a.k.a. Lief O'Pardy
  8.  
  9.                   Copyright (C) 1995,1996 by Jason Morriss
  10.  
  11.   v- All of the following crap can be ignored (except for the last paragraph)
  12.      I finally decided that this method will still require just about the
  13.      same amount of programming.  The Last paragraph discribes the best
  14.      option IMO.
  15.  
  16.   This unit contains the functions needed to read in a drop file that the
  17.   BBS creates when your DOOR is run.  I thought long and hard trying to
  18.   make this unit easy to use.  Since there are a countless number of
  19.   different Drop File formats, its hard to make it easy for the programmer
  20.   to support them all (or most), without a lot of extra programming.  I
  21.   finally decided to make a seperate RECORD for each format (only the ones
  22.   that i know are implemented).  But no variables of those types are declared
  23.   by this unit, Thats totally up to the programmer.  The method i can think
  24.   of that is the easiest to use (IMO), would be something like:
  25.     x) This method is useful because you only need to declare _1_ pointer,
  26.        and you can use all of the different types of drop files.  The method
  27.        below is only a suggestion, you don't have to use it.  You could also
  28.        declare a variable for each dropfile, and do it that way, but it takes
  29.        more memory that way... its a waste. anyways...
  30.     1) declare a pointer in your program (a generic pointer, that is... it
  31.        must not have a TYPE except of "pointer"; ie: p:pointer).
  32.     2) Decide which Dropfile you want to load (either through the command
  33.        line, or an INI file, etc), and getmem() memory for the pointer.  The
  34.        amount of memory it needs depends on which dropfile your going to
  35.        load.  Use the record types that i defined in the interface section.
  36.        (ie: sizeof(Tchain_txt))
  37.     3) Call the corresponding function to load the dropfile you want, passing
  38.        the pointer you created as the buffer to be filled.
  39.     4) Later in your program, whenever you need to get info from the pointer,
  40.        you have to TYPECAST the pointer to the corresponding dropfile record
  41.        needed.  Example:  port := Tchain_txt(p^).comport;
  42.        Looks weird?  it does kinda, but those that haven't seen anything
  43.        like this, its easy to understand.  What it does is, it "fools" TP
  44.        into thinking that p^ is actually of the type Tchain_txt, and not
  45.        a pointer, this way TP will calculate the offset needed to find the
  46.        "comport" variable in p^.
  47.    4a) If your going to support more then 1 dropfile then you'll have to
  48.        setup some sort of case statement everywhere you want to access info
  49.        from the dropfile buffer.  Just create a variable of the type
  50.        "Tdropfiles", and when you load a dropfile, change the variable to
  51.        the dropfile loaded. ie:
  52.          case DFloaded of
  53.            DFdorinfox_def : port := Tdorinfox_def(p^).comport;
  54.            DFchain_txt    : port := Tchain_txt(p^).comport;
  55.          end;
  56.        That does require a little more programming on your part, but i feel
  57.        that its minimal.
  58.  
  59.   Another method that would be a LOT easier is to make a seperate program
  60.   to read in the drop file that the sysop specifies, and extract all
  61.   important data from it (anything your door needs) into another file.
  62.   Then your door would only need to support that _1_ (one, uno) file, and
  63.   no extra programming is needed in the actual DOOR code!  At the time that
  64.   I write this, i have not made such a program... But I might create one for
  65.   this door library (its easy enough ;)
  66. }
  67. interface
  68.  
  69. uses dos;
  70.  
  71. type
  72.   string40 = string[40];
  73.   TUserSex = (SexUnknown,SexMale,SexFemale);
  74.   TDropFiles = (DFfake,DFdorinfox_def,DFchain_txt);   {known drop file types}
  75.  
  76.   TDorinfox_Def = record
  77.     Node       : byte;
  78.     BBSName    : string[40];
  79.     SysopName  : string[40];
  80.     {^ FName & LName are actually on seperate lines (LName is blank if none;
  81.        but the line for it is STILL there!)}
  82.     Comport    : byte;
  83.     Baudrate   : longint;
  84.     DataBits   : byte;
  85.     StopBits   : byte;
  86.     Parity     : char;
  87.     _Unknown_  : byte;       {this has always been 0 in my experience}
  88.     UserName   : string[40]; {could be an alias or real name (but mostly alias i think)}
  89.     {^ FName & LName are actually on seperate lines (LName is blank if none;
  90.        but the line for it is STILL there!)}
  91.     UserLoc    : string[40]; {ie: "Silver Spring, MD" [w/o quotes]}
  92.     UseAnsi    : boolean;
  93.     Seclevel   : integer;
  94.     BBSMinLeft : word;       {minutes left on BBS, when user entered DOOR}
  95.     UseFossil  : boolean;
  96.   end;
  97.  
  98.   TChain_Txt = record
  99.     UserNum      : word;
  100.     UserName     : string[40]; {user's ALIAS}
  101.     UserRealName : string[40];
  102.     UserCallSign : string[15];
  103.     {^ what the hell is "HAM radio"!?!?  In my 3½ years of BBSing, i've
  104.        never been able to find out! (i haven't really looked either ;)}
  105.     UserAge      : byte;
  106.     UserSex      : TUserSex;
  107.     UserGold     : Real;
  108.     LastLogon    : string[10]; {ie: "08/5/95" [w/o quotes]}
  109.     ScreenWidth  : byte;       {80 mostly}
  110.     ScreenLength : byte;       {24/25 mostly}
  111.     SecLevel     : integer;
  112.     IsCoSysop    : boolean;    {Is user a CoSysop?}
  113.     IsSysop      : boolean;    {Is user the Sysop?}
  114.     UseAnsi      : boolean;
  115.     Local        : boolean;    {Is user on locally?}
  116.     BBSsecLeft   : real;       {Seconds left on BBS, before entering DOOR}
  117.     GFILESpath   : string[80];
  118.     SYSDATApath  : string[80];
  119.     SYSLOGname   : string[12];
  120.     Baudrate     : longint;
  121.     Comport      : byte;
  122.     BBSname      : string[40];
  123.     SysopName    : string[40];
  124.     _Unknown_    : longint;    {# of secs after midnight... or something...?}
  125.     UserTotalSec : longint;
  126.     UserTotalULk : longint;
  127.     UserTotalUL  : word;
  128.     UserTotalDLk : longint;
  129.     UserTotalDL  : word;
  130.     DataBits     : byte; {this actually is written to the file like: "8N1". }
  131.     parity       : char; {"}
  132.     StopBits     : byte; {"}
  133.   end;
  134.  
  135. {const
  136.   AutoFillDoorRec : boolean = true;{}
  137.  
  138. {─--[headers]-──────────────────────────────────────────────────────────────}
  139. Function Read_Fake:boolean;
  140. {^ "fake" reading a dropfile.  This is to help you test your DOOR, w/o
  141.    needing a dropfile.  This will load in a bunch of default settings, so
  142.    you won't just have a zero dropfile record.  If you don't load a DropFile,
  143.    then all the comport info MUST be in the INI file, or you can get it from
  144.    the command line.  It is suggested though, that you always include an INI
  145.    file with your DOOR, its easier then using the command line, IMO. }
  146. Function Read_ChainTxt(fn:pathstr; var p):boolean;
  147. {^ Read in a CHAIN.TXT dropfile.
  148.    NOTE: This function is untested, but it should work fine.
  149.      fn = [d:\path\]filename to drop file.  If the file is in another
  150.           directory, then the entire path WILL need to be given.
  151.      P = Buffer to store the info.  Besure its large enough to hold the
  152.          entire record. }
  153. Function Read_DorinfoxDef(fn:pathstr; var p):boolean;
  154. {^ Read in a DORINFOx.DEF dropfile.
  155.    NOTE: This function has been tested, and it works.
  156.      fn = [d:\path\]filename to drop file.  If the file is in another
  157.           directory, then the entire path WILL need to be given.
  158.           The "X" in the filename is actually replaced (by the bbs) with
  159.           the node # of the user about to play your door.  It ranges from
  160.           0..9.  So the filename never actually has an "X" in it.
  161.      P = Buffer to store the info.  Besure its large enough to hold the
  162.          entire record. }
  163.  
  164. implementation
  165.  
  166. var
  167.   f : text;             {used in reading the drop files}
  168.   i,e : integer;        {"}
  169.   s,s2 : string;        {"}
  170.  
  171. {────────────────────────────────────────────────